package observer;

import java.util.LinkedList;
import java.util.List;

public abstract class ASubject<S> {
	protected S state ; //generic 
	List<IObserver<S>> observers = new LinkedList<IObserver<S>>(); 
	
	abstract public void setState(S value);
	
	abstract public S getState (); 
	
	public void attach(IObserver<S> observer){
		observers.add(observer);
	}
	
	public void dettach(IObserver<S> observer){
		observers.remove(observer);
	}
	
	public void notifyObservers(){
		for(IObserver<S> o : observers){
			o.update(state);
		}
	}
	
}
